from Networking import *
from Kamaelia.Util.Console import ConsoleEchoer
from Kamaelia.Internet.TCPClient import TCPClient

class TestCreatePlayerHandler(CreatePlayerHandler):
    def __call__(self,*argl):
        pl = CreatePlayerHandler.__call__(self,*argl)
        proto = Graphline(PLAYER_HANDLER  = pl,
                          ECHO = ConsoleEchoer(),     
                          linkages = {
                                      ("PLAYER_HANDLER", "outbox") : ("self", "outbox"),
                                      ("self", "inbox") : ("PLAYER_HANDLER", "inbox"),
                                      ("PLAYER_HANDLER", "commandOutbox") : ("ECHO", "inbox"),                                      
                                     }
                          )
        return proto

    
        
server=SimpleServer(protocol=TestCreatePlayerHandler(),
                    port=6666).activate()
                    
from Kamaelia.Util.PipelineComponent import pipeline
from Kamaelia.Util.Introspector import Introspector
from time import sleep
pipeline( Introspector(), TCPClient("127.0.0.1",1501) ).activate()                    
                    
                    
class CommandGen(component):
    Inboxes = {"inbox" : "","control" : ""}
    Outboxes = {"outbox" : "","signal" : ""}
        
    def main(self):
        for x in xrange(0,100):
            yield 1
            self.send(("CommandTest",1,2,3,4,5),"outbox")
            sleep(1)
            
    def shutdown(self):
        if self.dataReady("control"):
            msg = self.recv("control")
            if(isinstance(msg, Axon.Ipc.producerFinished)):
                self.send(msg,"signal")
                return True
            return False 
                    

Graphline(GEN = CommandGen(),
          COMMANDIZER = Commandizer(),
          PACKETIZER  = Packetizer(),
          CLIENT = TCPClient("127.0.0.1",6666),
          linkages = {
                      ("GEN","outbox") : ("COMMANDIZER", "writeInbox"),
                      ("COMMANDIZER", "writeOutbox") : ("PACKETIZER","writeInbox"),
                      ("PACKETIZER", "writeOutbox") : ("CLIENT","inbox"),
                      
                      ("CLIENT", "outbox") : ("PACKETIZER","readInbox"),
                      ("PACKETIZER", "readOutbox") : ("COMMANDIZER","readInbox"),                      
                     }
        ).run()                    
